package com.example.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.shop.pojo.Evaluation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface EvaluationMapper extends BaseMapper<Evaluation> {

    @Select("select EXISTS(" +
                "select e.evaluation_id,e.user_id,rec.comments_user_id,recr.comments_user_id " +
                "from evaluation e " +
                "left join r_evaluation_comments rec on e.evaluation_id = rec.evaluation_id " +
                "left join r_evaluation_comments_reply recr on e.evaluation_id = recr.evaluation_id " +
                "where e.evaluation_id = ${evaluationId} " +
                "and (rec.comments_user_id = ${replyUserId} or e.user_id = ${replyUserId} or recr.comments_user_id = ${replyUserId}) " +
            ")")
    boolean existReplyUser(@Param("evaluationId") long evaluationId, @Param("replyUserId") long replyUserId);
}
